using WebAPI.Filter;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

// Add services to the container.
builder.Services.AddControllersWithViews(options =>
{
    options.Filters.Add<UserAuthorizationFilter>();
});

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}


// 设置只允许特定来源可以跨域
app.UseCors(options =>
{
    options.WithOrigins("http://localhost:8080", "http://127.0.0.1"); // 允许特定ip跨域
    options.AllowAnyHeader();
    options.AllowAnyMethod();
    options.AllowCredentials();
});

// app.UseCors("myCors");

app.UseAuthentication();

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();